package com.buka.communicate.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.buka.communicate.R;
import com.facebook.drawee.view.SimpleDraweeView;

import net.neiquan.applibrary.base.BaseActivity;
import net.neiquan.applibrary.numberpicker.view.AlertDatePicker;
import net.neiquan.applibrary.wight.AlertChooser;
import net.neiquan.applibrary.wight.CommonPopupWindow;

import java.util.Date;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/11/10 0010.
 */

public class InfoCompleteActivity extends BaseActivity {
    @InjectView(R.id.backFL)
    FrameLayout backFL;
    @InjectView(R.id.mHeadImg)
    SimpleDraweeView mHeadImg;
    @InjectView(R.id.photoFL)
    FrameLayout photoFL;
    @InjectView(R.id.nameEv)
    EditText nameEv;
    @InjectView(R.id.nameLL)
    LinearLayout nameLL;
    @InjectView(R.id.sexTv)
    TextView sexTv;
    @InjectView(R.id.sexLL)
    LinearLayout sexLL;
    @InjectView(R.id.birthTv)
    TextView birthTv;
    @InjectView(R.id.birthLL)
    LinearLayout birthLL;
    @InjectView(R.id.loginCardView)
    CardView loginCardView;
    @InjectView(R.id.agreeLogo)
    ImageView agreeLogo;
    @InjectView(R.id.agreeLL)
    LinearLayout agreeLL;
    @InjectView(R.id.infoCompleteLL)
    LinearLayout infoCompleteLL;

    @Override
    public int getRootViewId() {
        return R.layout.activity_info_complete;
    }

    @Override
    public void setViews() {
        mHeadImg.setImageURI("http://img2.imgtn.bdimg.com/it/u=266057472,3867980612&fm=27&gp=0.jpg");
    }

    @Override
    public void initData() {

    }

    @OnClick({R.id.backFL, R.id.photoFL, R.id.nameLL, R.id.sexLL, R.id.birthLL, R.id.loginCardView, R.id.agreeLL})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.backFL:
                finish();
                break;
            case R.id.photoFL:
                showAlertChooser();
                break;
            case R.id.nameLL:
                break;
            case R.id.sexLL:
                showSexPopWindow();
                break;
            case R.id.birthLL:
                new AlertDatePicker.Builder(InfoCompleteActivity.this)
                        .setTitle(getResources().getString(R.string.starByBirth))
                        .setDateSelectListener(new AlertDatePicker.OnDateSelectListener() {
                            @Override
                            public void endSelect(Date selectDate, String selectDateStr, boolean isCancel) {
                                birthTv.setText(selectDateStr);
                            }
                        }).show();
                break;
            case R.id.loginCardView:
                startActivity(new Intent(InfoCompleteActivity.this, LoginActivity.class));
                break;
            case R.id.agreeLL:
                break;
        }
    }

    private void showAlertChooser() {
        new AlertChooser.Builder(this).setTitle("选择图片").addItem("相机", new AlertChooser.OnItemClickListener() {
            @Override
            public void OnItemClick(AlertChooser chooser) {
                chooser.dismiss();
            }
        }).addItem("相册", new AlertChooser.OnItemClickListener() {
            @Override
            public void OnItemClick(AlertChooser chooser) {
                chooser.dismiss();
            }
        }).setNegativeItem("取消", new AlertChooser.OnItemClickListener() {
            @Override
            public void OnItemClick(AlertChooser chooser) {
                chooser.dismiss();
            }
        }).show();
    }

    private void showSexPopWindow() {
        CommonPopupWindow popupWindow = new CommonPopupWindow.Builder(this)
                //设置PopupWindow布局
                .setView(R.layout.layout_sex_select)
                //设置宽高
                .setWidthAndHeight(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT)
                //设置动画
                .setAnimationStyle(R.style.Animation_pushUp)
                //设置背景颜色，取值范围0.0f-1.0f 值越小越暗 1.0f为透明
                .setBackGroundLevel(0.5f)
                //设置PopupWindow里的子View及点击事件
                .setViewOnclickListener(new CommonPopupWindow.ViewInterface() {
                    @Override
                    public void getChildView(final PopupWindow popupWindow, View view, int layoutResId) {
                        TextView cancel_tv = (TextView) view.findViewById(R.id.cancel_tv);
                        TextView confirm_tv = (TextView) view.findViewById(R.id.confirm_tv);
                        FrameLayout manSexFL = (FrameLayout) view.findViewById(R.id.manSexFL);
                        FrameLayout womanSexFL = (FrameLayout) view.findViewById(R.id.womanSexFL);
                        final ImageView manChoseLogo = (ImageView) view.findViewById(R.id.manChoseLogo);
                        final ImageView womanChoseLogo = (ImageView) view.findViewById(R.id.womanChoseLogo);
                        cancel_tv.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                popupWindow.dismiss();
                            }
                        });
                        confirm_tv.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                popupWindow.dismiss();
                            }
                        });
                        manSexFL.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                manChoseLogo.setVisibility(View.VISIBLE);
                                womanChoseLogo.setVisibility(View.GONE);
                            }
                        });
                        womanSexFL.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                manChoseLogo.setVisibility(View.GONE);
                                womanChoseLogo.setVisibility(View.VISIBLE);
                            }
                        });
                    }
                })
                //设置外部是否可点击 默认是true
                .setOutsideTouchable(true)
                //开始构建
                .create();
        //弹出PopupWindow
        popupWindow.showAtLocation(infoCompleteLL, Gravity.BOTTOM, 0, 0);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.inject(this);
    }
}
